Imports CapaDeDatos
Public Class nOrdendePago
    Private Proveedor As CapaDeNegocios.nProveedor = New CapaDeNegocios.nProveedor
    Private OrdendePago As CapaDeDatos.dOrdendePago = New CapaDeDatos.dOrdendePago()
    Private DetalleOp As CapaDeNegocios.nDetalleOrdenDePago = New CapaDeNegocios.nDetalleOrdenDePago
    Public Function Insertar(ByVal Importe As String, ByVal IdProveedor As String, ByVal Observacion As String) As DataSet
        Return OrdendePago.Insertar(Importe, IdProveedor, Observacion)
    End Function
    Public Function Eliminar(ByVal CodigoOrdendePago As String) As Boolean
        Return OrdendePago.Eliminar(CodigoOrdendePago)
    End Function
    Public Function BuscarFiltrado(ByVal CodigoOrdendePago As String, ByVal Fecha As String, ByVal Importe As String, ByVal IdProveedor As String, ByVal Observacion As String) As DataSet
        Dim dts As DataSet
        dts = OrdendePago.BuscarFiltrado(CodigoOrdendePago, Fecha, Importe, IdProveedor, Observacion)
        dts.Tables(0).Columns.Add("Numero")
        dts.Tables(0).Columns.Add("Proveedor")
        Dim i As Integer
        For i = 0 To dts.Tables(0).Rows.Count - 1
            Try
                dts.Tables(0).Rows(i)("Numero") = "OP-0001-" + dts.Tables(0).Rows(i)("CodigoOrdenDePago").ToString().PadLeft(8).Replace(" ", "0")
            Catch ex As Exception
                dts.Tables(0).Rows(i)("Numero") = dts.Tables(0).Rows(i)("CodigoOrdenDePago").ToString()
            End Try
            Try
                dts.Tables(0).Rows(i)("Proveedor") = Proveedor.Listar(dts.Tables(0).Rows(i)("idProveedor").ToString(), "", "", "", "", "", "", "").Tables(0).Rows(0)("RazonSocial").ToString()
            Catch ex As Exception
                dts.Tables(0).Rows(i)("Proveedor") = dts.Tables(0).Rows(i)("idProveedor").ToString()
            End Try
        Next
        Return dts
    End Function
    Public Function ImprimirOrden(ByVal CodigoOrdendePago As String) As DataSet
        Dim Dts As DataSet
        Dim DtsDeta As DataSet
        Dts = OrdendePago.BuscarFiltrado(CodigoOrdendePago, "", "", "", "")
        Dts.Tables(0).Columns.Add("Numero")
        Dts.Tables(0).Columns.Add("Proveedor")
        Dts.Tables(0).Columns.Add("Comprobante")
        Dts.Tables(0).Columns.Add("Subtotal")
        DtsDeta = DetalleOp.BuscarFiltrado("", "", "", CodigoOrdendePago)

        Dim i As Integer
        Dim j As Integer
        For i = 0 To Dts.Tables(0).Rows.Count - 1
            Try
                Dts.Tables(0).Rows(i)("Numero") = "OP-0001-" + Dts.Tables(0).Rows(i)("CodigoOrdenDePago").ToString().PadLeft(8).Replace(" ", "0")
            Catch ex As Exception
                Dts.Tables(0).Rows(i)("Numero") = Dts.Tables(0).Rows(i)("CodigoOrdenDePago").ToString()
            End Try
            Try
                Dts.Tables(0).Rows(i)("Proveedor") = Proveedor.Listar(Dts.Tables(0).Rows(i)("idProveedor").ToString(), "", "", "", "", "", "", "").Tables(0).Rows(0)("RazonSocial").ToString()
            Catch ex As Exception
                Dts.Tables(0).Rows(i)("Proveedor") = Dts.Tables(0).Rows(i)("idProveedor").ToString()
            End Try

            For j = 0 To DtsDeta.Tables(0).Rows.Count - 1
                Try
                    Dts.Tables(0).Rows(i)("Comprobante") = DtsDeta.Tables(0).Rows(j)("Factura").ToString()
                Catch ex As Exception
                    Dts.Tables(0).Rows(i)("Comprobante") = "No Existe Detalle"
                End Try
                Try
                    Dts.Tables(0).Rows(i)("Subtotal") = DtsDeta.Tables(0).Rows(j)("Total").ToString()
                Catch ex As Exception
                    Dts.Tables(0).Rows(i)("Subtotal") = "No Existe Subtotal"
                End Try
            Next
        Next
        Return Dts
    End Function
End Class
